﻿import $ from 'jquery';

export class Utils {

    static GetDoms = function (content: string[], all: boolean = true) {
        content = content.remove([''])

        var doms = Array.from($(content[0] + ":visible", document));
        doms.forEach(t => {
            $(t).attr("contentIndex", 0);
        });

        var results = doms.slice(0);

        for (var i = 1; i < content.length; i++) {
            let tmp: HTMLElement[] = [];
            doms.forEach(o => {
                var c = Array.isArray(content[i]) ? Array.from(content[i]) : [content[i]];
                c.forEach((ct) => {
                    tmp.push(...$(ct + ":visible", o));
                });
            });
            doms = tmp;
            tmp.forEach(t => {
                $(t).attr("contentIndex", i);
            });
            if (all)
                results.push(...tmp);
            else
                results = tmp;
        }

        return results;
    };
};